package org.dftproject.gedcom.ui;

import org.dftproject.gedcom.core.Gedcom;
import org.dftproject.genesis.data.genealogy.GenealogyConstants;
import org.dftproject.genesis.data.genealogy.GenealogyUtils;
import org.dftproject.genesis.data.genealogy.ISource;
import org.dftproject.genesis.ui.citations.ICitation;
import org.dftproject.genesis.ui.citations.ICitationFormatter;
import org.dftproject.genesis.ui.figures.IHyperlinkListener;

public class GedcomCitationFormatter implements ICitationFormatter {

	public void format(ICitation citation, ISource source) {
		Gedcom gedcom = (Gedcom) GenealogyUtils.getValue(source, GenealogyConstants.collection, Gedcom.class);
		String title = (String) GenealogyUtils.getValue(source, GenealogyConstants.title, String.class);
		if (title == null)
			title = "(unknown)";
		
		citation.addHyperlink(title, new IHyperlinkListener() {

			public void linkActivated(Object data, int stateMask) {
				//
			}
				
		});
		
		citation.addText(", GEDCOM.");

		String id = (String) GenealogyUtils.getValue(source, "id", String.class);
		if (id != null) {
			citation.addText(" ");
			citation.addHyperlink(id, new IHyperlinkListener() {

				public void linkActivated(Object data, int stateMask) {
					//
				}
				
			});
			citation.addText(".");
		}
	}
	
}
